package com.glsc.ngateway.ldap.enums;

import com.glsc.ngateway.common.api.ldap.dto.LdapUserDto;
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.constraints.NotNull;

/**
 * @author xuchang
 */

@AllArgsConstructor
@Getter
public enum CheckInterfaceParamsInterfaceIdEnum {
    LOGIN_CODE("login", userDto -> userDto.getUserName() != null && userDto.getSystemId() != null && userDto.getPassword() != null),
    LOGIN_PORTAL("loginPortal", userDto -> userDto.getUserName() != null && userDto.getSystemId() != null && userDto.getPassword() != null && userDto.getTryCode() != null),
    LOGIN_PORTAL_CODE("loginPortal", userDto -> userDto.getUserName() != null && userDto.getSystemId() != null && userDto.getPassword() != null),
    CHECK_TOKEN("checkToken", userDto -> userDto.getSystemId() != null && userDto.getToken() != null),
    RENEW_TOKEN("renewTokenExpire", userDto -> userDto.getToken() != null && userDto.getSystemId() != null && userDto.getDelayHours() != null),
    KICKOUT_TOKEN("kickOutToken", userDto -> userDto.getToken() != null && userDto.getSystemId() != null),
    PORTAL_CHECK_TOKEN("portalCheckToken", userDto -> userDto.getToken() != null && userDto.getSystemId() != null),
    ;

    private final String code;
    private final Checker checker;

    public boolean check(@NotNull LdapUserDto ldapUserDto){
        return this.getChecker().check(ldapUserDto);
    }
    @FunctionalInterface
    public interface Checker {
        /**
         * 检查方法
         */
        boolean check(LdapUserDto user);
    }
}


